<?php

namespace App\Admin\Controllers;

use App\Services\IdcnodeService;
use Slowlyo\OwlAdmin\Controllers\AdminController;

/**
 * IDC机房管理
 *
 * @property IdcnodeService $service
 */
class IdcnodeController extends AdminController
{
	protected string $serviceName = IdcnodeService::class;

	public function index()
	{
			$idc_belong = request()->input('idc_belong');
			if ($this->actionOfGetData()) {
				return $this->service->getData($idc_belong);
			}


		// 没有携带 _action 参数的请求, 返回列表结构
		return $this->response()->success($this->list()); // 这里调用了 list 方法
	}

	public function list()
	{
		
		$crud = $this->baseCRUD()
			->filterTogglable(false)
			->headerToolbar([
				$this->createButton('dialog'),
				...$this->baseHeaderToolBar()
			])
			->columns([
				amis()->TableColumn('id', 'ID')->sortable(),
				amis()->TableColumn('idc_name', 'IDC节点名称'),

				
				amis()->TableColumn('idc_belong', 'IDC节点归属')->type('each')->items(
					amis()->Tpl()->tpl('${item == 1 ? "[客户端]" : (item == 2 ? "[供应商]" : "[运营商]")}')
				),
			


				amis()->TableColumn('idc_contact', '机房联系人'),
				amis()->TableColumn('idc_phone', '机房电话'),
				amis()->TableColumn('idc_address', '机房地址'),
				amis()->TableColumn('idc_remark', '机房备注'),
				amis()->TableColumn('operator.name', '操作人')->sortable(),
				
				amis()->TableColumn('created_at', admin_trans('admin.created_at'))->type('date')->sortable(),
				$this->rowActions('dialog')
			]);

		return $this->baseList($crud);
	}

	public function form($isEdit = false)
	{
		return $this->baseForm()->body([
			amis()->TextControl('idc_name', 'IDC节点名称'),
			amis()->SelectControl('idc_belong', 'IDC节点归属')
				->multiple(true)
				->options([
					['label' => '客户侧流量统计', 'value' => 1],
					['label' => '供应商流量统计', 'value' => 2],
					['label' => '运营商流量统计', 'value' => 3],
				]),
			amis()->GroupControl()->body([
				amis()->TextControl('idc_contact', '机房联系人'),
				amis()->TextControl('idc_phone', '机房电话'),
			]),
			amis()->TextControl('idc_address', '机房地址'),
			amis()->TextareaControl('idc_remark', '机房备注'),
		
		]);
	}

	public function detail()
	{
		return $this->baseDetail()->body([
			amis()->TextControl('id', 'ID')->static(),
			amis()->TextControl('add_time', '添加时间')->static(),
			amis()->TextControl('editor_uid', '编辑人UID')->static(),
			amis()->TextControl('idc_name', '位置名称')->static(),
			amis()->TextControl('idc_remark', '位置备注')->static(),
			amis()->TextControl('operator_uid', '操作人UID')->static(),
			amis()->TextControl('soft_delete', '软删除标识（0未删除，1已删除）')->static(),
			amis()->TextControl('sort_order', '排序')->static(),
			amis()->TextControl('update_time', '更新时间')->static(),
			amis()->TextControl('created_at', admin_trans('admin.created_at'))->static(),
			amis()->TextControl('updated_at', admin_trans('admin.updated_at'))->static(),
		]);
	}

	public function getData()
	{
		$idc_belong = request()->input('idc_belong');
		var_dump($idc_belong);die;
		
	}
}